package com.ruoyi.web.controller.system;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.system.domain.CollectionUp;
import com.ruoyi.system.service.CollectionUpService;
import com.ruoyi.web.controller.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *收藏
 * */
@RestController
public class CollectionController {

    @Autowired
    private CollectionUpService collectionUpService;
    //添加收藏
    @PostMapping("/saveColl")
    public R<String> saveColl(CollectionUp collection){
        collectionUpService.save(collection);
        return R.success("收藏成功");
    }
    //删除收藏
    @DeleteMapping("/deleteColl")
    private R<String> deleteColl(int id){
        collectionUpService.removeById(id);
        return R.success("删除成功");
    }
    //查询收藏
    @PostMapping("/selectCollByid")
    public R<List<CollectionUp>> selectColl(int userId){
        LambdaQueryWrapper<CollectionUp> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CollectionUp::getUserId,userId);
        List<CollectionUp> list = collectionUpService.list(queryWrapper);
        return R.success(list);
    }
    //查询收藏通过名字
    @PostMapping("/selectCollByname")
    public R<List<CollectionUp>> selectCollByName(String str){
        LambdaQueryWrapper<CollectionUp> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(CollectionUp::getCollName,str).orderByAsc(CollectionUp::getId);
        List<CollectionUp> list = collectionUpService.list(queryWrapper);
        return R.success(list);
     }

}
